import flixel.FlxObject;
import flixel.FlxSprite;
import flixel.FlxG;

class Pucky extends FlxSprite
{
	//--------------------------------------------------------------------------------//
	//---*Atributos:
	//--------------------------------------------------------------------------------//
	//---*Estados:
	private static inline var GRAVITY: Float = 900;
	private static inline var JUMP_SPEED: Float = 400;
	private static inline var DOUBLE_JUMP_SPEED: Float = JUMP_SPEED * (2/3);
	private static inline var DOUBLE_JUMP_GAP: Float = 128;
	private var canDoubleJump: Bool = false;

	
	//--------------------------------------------------------------------------------//
	//---*Metodos:
	//--------------------------------------------------------------------------------//
	override public function new(x: Float, y: Float)
	{
		super(x, y);
		acceleration.y = 250;
		loadGraphic("assets/images/pucky.png", true, false, 16, 16);
		animation.add("eating", [0, 1, 2, 1, 0], 15);
		animation.play("eating");
		this.acceleration.y = GRAVITY;	
	}

	override public function update()
	{
		if (FlxG.mouse.justPressed)
		{
			if (isTouching(FlxObject.FLOOR))
			{
				velocity.y = -JUMP_SPEED;
				canDoubleJump = true;
			}
			else if (canDoubleJump && (velocity.y >= -DOUBLE_JUMP_GAP && velocity.y <= 0))
			{
				velocity.y = -DOUBLE_JUMP_SPEED;
				canDoubleJump = false;
			}
		}
		super.update();
	}
	
	

}